<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

	<div id="partnerZoom" class="easyui-window" title="Selecionar Parceiros" data-options="modal:true,closed:true" style="width:800px;height:500px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">

				<table id="dgPartners" class="easyui-datagrid" title="" 
					data-options="rownumbers:true,singleSelect:true, method:'get',toolbar:'#tbPartners', pagination:true, fitColumns:true,onClickRow: onClickRow">
					<thead>
						<tr>
							<th data-options="field:'id',width:10">Id</th>
							<th data-options="field:'name',width:80,align:'left'">Nome</th>
						</tr>
					</thead>
				</table>
	
				<div id="tbPartners" style="padding:5px;height:auto">
					<div>
						Nome: <input id="partnerName" class="easyui-textbox" style="width:150px">
						<a href="#" onclick="searchPartner();" class="easyui-linkbutton" iconCls="icon-search">Pesquisar</a>
					</div>
				</div>

			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" href="javascript:void(0)" onclick="javascript:selectPartnerZoom();">Selecionar</a>
				<a class="easyui-linkbutton" href="javascript:void(0)" onclick="javascript:closePartnerZoom();">Cancelar</a>
			</div>
		</div>
	</div>

    <form:form id="partnerZoomForm" action="${pageContext.request.contextPath}/secure/partnerZoom.html" method="POST" modelAttribute="partner">
		<form:hidden id="partnerZoomName" path="name"/>
	</form:form>		

<script type="text/javascript">

	function searchPartner(){
		$("#partnerZoomName").val($("#partnerName").val());
        items = {};
        items = $("#partnerZoomForm").serializeForm();
        url = $("#partnerZoomForm").attr("action");

		callback = function (data){
			var obj = jQuery.parseJSON( data );
			$('#dgPartners').datagrid('loadData', obj ); 
		};

        $.post(url,items,callback);
	}

	function selectPartnerZoom(){
		var row = $('#dgPartners').datagrid('getSelected');
		if (row){
			$('#partner').val(row.id);
			$('#partnerDescription').text(row.name);
			closePartnerZoom();
		}
	}

	function openPartnerZoom(){
		searchPartner();
		$('#partnerZoom').window('open');
	}
	function closePartnerZoom(){
		$('#partnerZoom').window('close');
	}

</script>
	